$(function () {
	function GoUrl(){
			location.href='giftExchangePre.action?giftId=' + window.giftId;
	}
   var rotateFunc = function (angle) {  //awards:奖项，angle:奖项对应的角度
       $('#lotteryBtn').stopRotate();
       $("#lotteryBtn").rotate({
           angle: 0,
           duration: 5000,
           animateTo: angle + 1440, //angle是图片上各奖项对应的角度，1440是我要让指针旋转4圈。所以最后的结束的角度就是这样子^^
           callback: function () {
			   window.run = false;
			  var count =  $('.BigRad').html();
			  count = ~~count;
			  if(count > 0){
				  count --;
			  }
			  $('.BigRad').html(count)
				setTimeout(GoUrl, 1000);
           }
       });
   };
   $("#btnstart").rotate({
       bind: {
           click: function () {
        	   if(window.run){
        		   return false;
        	   }
        	   $.ajax({
        		   url: 'ajaxLoterry.action',
        		   cache: false,
        		   success: function(json){
        			   json = tohours.parseJSON(json);
        			   if(json.success){
        				   var angles = [315, 225, 270, 45, 135, 180, 0, 90];
        				   window.run = true;
        				   window.giftId = json.giftId;
        	               rotateFunc(angles[json.loterry - 1], '恭喜您抽中奖');
        			   } else {
        				   alert(json.msg);
        			   }
        		   }
        	   });
           }
       }
   });
	
	$('.modalLink').modal({
	   trigger: '.modalLink',          // id or class of link or button to trigger modal
	   olay:'div.overlay',             // id or class of overlay
	   modals:'div.modal',             // id or class of modal
	   animationEffect: 'slideDown',   // overlay effect | slideDown or fadeIn | default=fadeIn
	   animationSpeed: 400,            // speed of overlay in milliseconds | default=400
	   moveModalSpeed: 'slow',         // speed of modal movement when window is resized | slow or fast | default=false
	   background: '000000',           // hexidecimal color code - DONT USE #
	   opacity: 0.7,                   // opacity of modal |  0 - 1 | default = 0.8
	   openOnLoad: false,              // open modal on page load | true or false | default=false
	   docClose: true,                 // click document to close | true or false | default=true    
	   closeByEscape: true,            // close modal by escape key | true or false | default=true
	   moveOnScroll: true,             // move modal when window is scrolled | true or false | default=false
	   resizeWindow: true,             // move modal when window is resized | true or false | default=false
	   videoClass:'video',             // class of video element(s)
	   close:'.closeBtn'               // id or class of close button
	});
	$('.modalLink').click(function(){
		$.ajax({
			url: 'giftList.action',
			cache: false,
			success: function(html){
				$('.bd').html(html);
			}
		});
		return false;
	});
});